#include<iostream>
using namespace std;
long long jc(long long n)
{
	long long j=1;
	for(long long i=1;i<=n;i++)
	{
		j*=i;
		j%=1000000007;
	}
	return j;
}
long long Cantor(int len,int buf[])
{
	int i,j,counted;
	long long result=1;
	for (i=0;i<len;++i)
	{
		counted=0;
		for(j=i+1;j<len;++j)
			if(buf[i]>buf[j])
				++counted;
		result+=(counted*jc(len-i-1))%1000000007;
	}
	return result;
}
int main()  
{ 
	int num;
	cin>>num;
    int a[num];
	for(int data=0;data<num;data++)
	{
		cin>>a[data];
	}
    cout<<Cantor(num,a)%1000000007<<endl;
    return 0;
}  
